﻿/* * 版 本 PIT-ADMS V7.0.3 敏捷开发框架
 * Copyright (c) 2013-2018 Hexagon PPM
 * 创建人：chenkai
 * 日  期：2022-02-24
 * 描  述：属性设置
 */
var refreshGirdData;
var PropertyGID = "";
var ObjectTypeID = request('ObjectTypeID');
var selectData = [];
var ProjectId = request('ProjectId');
var bootstrap = function ($, learun) {
    "use strict";
    var page = {
        init: function () {
            page.bind();
            page.initGird();
        },
        bind: function () {
            // 初始化左侧树形数据
            $('#dataTree').lrtree({
                url: top.$.rootUrl + '/ZZDT_EC/ec_property/GetTree?ProjectId=' + ProjectId,
                nodeClick: function (item) {
                    $("#titleinfo").html(item.text);
                    PropertyGID = item.value;
                    page.search();
                }
            });

            //获取当前选中的数据
            $.ajax({
                url: top.$.rootUrl + '/ZZDT_EC/ec_property/GetObjectTypePById',
                data: { objectTypeID: ObjectTypeID, ProjectId: ProjectId },
                async: false,
                type: "GET",
                dataType: "json",
                success: function (data) {
                    if (data.code == 200 && data.data.length > 0)
                        selectData = data.data;
                },
                error: function () {
                },
                complete: function (data) {
                }
            });

            //查询
            $('#btn_Search').on('click', function () {
                page.search();
            });
            // 刷新
            $('#lr_refresh').on('click', function () {
                location.reload();
            });
            // 保存
            $('#lr_save').on('click', function () {
                var postData = {
                    strEntity: JSON.stringify(selectData)
                }
                $.lrSaveForm(top.$.rootUrl + '/ZZDT_EC/ec_property/SaveObjectTypeP?objectTypeID=' + ObjectTypeID + "&ProjectId=" + ProjectId, postData, function (res) {

                });
            });
        },
        // 初始化列表
        initGird: function () {
            $('#gridtable').jfGrid({
                url: top.$.rootUrl + '/ZZDT_EC/ec_property/GetPageList',
                headData: [
                    { label: "属性名称", name: "PropertyName", width: 400, align: "left", sort: false },
                    { name: "", width: 1, sort: false }
                ],
                mainId: 'PropertyID',
                isPage: true,
                isMultiselect: true,
                onSelectRow: function (rowData, isSelect) {
                    selectData = $.grep(selectData, function (item) {
                        return item.PropertyID != rowData.PropertyID;
                    });
                    if (isSelect) {
                        var param = {};
                        param.ObjectTypePID = top.learun.newGuid();
                        param.PropertyID = rowData.PropertyID;
                        param.ObjectTypeID = ObjectTypeID;
                        selectData.push(param);
                    }
                },
                onRenderComplete: function (data) {
                    //默认已经选中的
                    for (var i = 0; i < data.length; i++) {
                        if (selectData) {
                            var gdata = $.grep(selectData, function (item) {
                                return item.PropertyID == data[i].PropertyID
                            });
                            if (gdata && gdata.length > 0) {
                                $('#gridtable').jfGridSet("selectRow", data[i].PropertyID);
                            }
                        }
                    }
                }
            });
            page.search();
        },
        search: function (param) {
            param = param || {};
            param.PropertyGID = PropertyGID;
            param.ProjectId = ProjectId;
            param.PropertyName = $("#PropertyName").val();
            $('#gridtable').jfGridSet('reload', { queryJson: JSON.stringify(param) });
        }
    };
    refreshGirdData = function () {
        $('#gridtable').jfGridSet('reload');
    };
    page.init();
}